// component/j-bespeak/j-bespeak.js
var app = getApp();
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {

	},

	/**
	 * 组件的初始数据
	 */
	data: {

	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		bindDateChange: function (e) {
			console.log('picker发送选择改变，携带值为', e.detail.value)
			this.setData({
				date: e.detail.value
			})
		},
		submit: function (e) {
			console.log(e);
			var that = this;
			if (e.detail.value.name.length == 0) {
				wx.showToast({
					title: '姓名不能为空',
					image: '../../images/error.png',
					duration: 1000
				})
			}
			else if (!(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value.tell))) {
				wx.showToast({
					title: '电话不能为空或格式有误',
					image: '../../images/error.png',
					duration: 1000
				})
			}
			// else if (e.detail.value.time.length == 0) {
			// 	wx.showToast({
			// 		title: '时间不能为空',
			// 		image: '../../images/error.png',
			// 		duration: 1000
			// 	})
			// }
			else if (e.detail.value.px.length == 0) {
				wx.showToast({
					title: '项目不能为空',
					image: '../../images/error.png',
					duration: 1000
				})
			}
			else {
				wx.request({
					url: 'https://xcxu.we-fs.com/index.php/api/goods/order1',
					method: 'post',
					data: {
						'name': e.detail.value.name,
						'sj': e.detail.value.tell,
						// 'pre_time': e.detail.value.time,
						// 'dz': '备注:' + e.detail.value.p,
						'goods_name': '【预约】' + e.detail.value.px,
						'admin_id': app.globalData.admin_id,
						'openid': app.globalData.openid,
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function (res) {
						console.log(res.data)

						that.setData({
							list: res.data[0],
						})
						wx.showToast({
							title: '预约成功',
							icon: 'success',
							duration: 2000,
							success: function () {
								setTimeout(function () {
									wx.switchTab({
										url: '../../pages/index/index',
									})
								}, 1500)
							}
						})
						setTimeout(function () {
							that.setData({
								loadingHidden: true
							})
						}, 1500)
					},
					fail: function (res) {
						console.log(res);
						wx.showToast({
							title: '预约失败！',
							duration: 2000
						})
					}
				})
			}
		}
	}
})
